package com.sinosoft.msf.base.supplier.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.sinosoft.msf.base.supplier.dao.base.SCompanyNotifyMapper;
import com.sinosoft.msf.base.supplier.pojo.entity.SCompanyNotify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class NotifyService {
    @Autowired
    SCompanyNotifyMapper notifyMapper;

    public List<SCompanyNotify> query() {
        Example exp = new Example(SCompanyNotify.class);
        exp.createCriteria().andEqualTo("deleted", "n");
        exp.orderBy("createdDate").desc();
        return notifyMapper.selectByExample(exp);
    }
    public void add(String txt) {
        SCompanyNotify notify = new SCompanyNotify();
        notify.setContent(txt);
        notify.setId(IdUtil.simpleUUID());
        notify.setDeleted("n");
        notify.setCreatedDate(DateUtil.date());
        notifyMapper.insert(notify);
    }

    public void del(SCompanyNotify notify) {
        SCompanyNotify updateModel = new SCompanyNotify();
        updateModel.setId(notify.getId());
        updateModel.setDeleted("y");
        notifyMapper.updateByPrimaryKey(updateModel);

    }
}
